<template>
  <div class="mv-container">
    <div class="mv-wrap">
      <h3 class="title">MV详情</h3>
      <div class="video-wrap">
        <video :src="videoUrl" controls autoplay></video>
      </div>
      <!-- mv信息 -->
      <div class="info-wrap">
        <div class="singer-info">
          <div class="avatar-wrap">
            <img :src="iconInfo" alt=""/>
          </div>
          <span class="name">
            {{ mvInfoObj.artistName}}
          </span>
        </div>
        <div class="mv-info">
          <h2 class="title">
            {{ mvInfoObj.name}}
          </h2>
          <span class="date">发布日期</span>
          <span class="number">
            {{mvInfoObj.playCount | changeCount }}
          </span>
          <p class="dec">
            {{ mvInfoObj.desc}}
          </p>
        </div>
      </div>
      <!--  精彩评论 -->
      <div class="comment-wrap">
        <p class="title">精彩评论</p>
        <div class="comments-wrap">
          <div class="item"
          v-for="(commentObj, index) in hotCommentList" :key="index">
            <div class="icon-wrap">
              <img :src="commentObj.user.avatarUrl" alt=""/>
            </div>
            <div class="content-wrap">
              <div class="content">
                <span class="name">{{commentObj.user.nickname}}</span>
                <span class="comment">
                  {{commentObj.content}}
                </span>
              </div>
              <div class="re-content" v-if="commentObj.beReplied.length != 0">
                <span class="name">{{commentObj.beReplied[0].user.nickname}}</span>
                <span class="comment">
                  {{commentObj.beReplied[0].content}}
                </span>
              </div>
              <div class="date"></div>
            </div>
          </div>
        </div>
      </div>
      <!--  最新评论 -->
      <div class="comment-wrap">
        <p class="title">最新评论</p>
        <div class="comments-wrap">
          <div class="item"
          v-for="(newObj, index) in newCommentList"
          :key="index">
            <div class="icon-wrap">
              <img :src="newObj.user.avattarUrl" alt=""/>
            </div>
            <div class="content-wrap">
              <div class="content">
                <span class="name">{{newObj.user.nickname}}</span>
                <span class="comment">
                  {{newObj.content}}
                </span>
              </div>
              <div class="re-content" v-if="newObj.beReplied.length != 0">
                <span class="name">
                  {{newObj.beReplied[0].user.nickname}}</span>
                <span class="comment">
                  {{newObj.beReplied[0].content}}
                </span>
              </div>
              <div class="date"></div>
            </div>
          </div>
        </div>
      </div>
      <el-pagination
      background
      layout="prev, pager, next"
      :total="total"
      :limit="limit"
      :page-size="5"
      :current-page="page"
      @current-change="handleCurrentChange">
      </el-pagination>
    </div>
    <div class="mv-recommend">
      <h3 class="title">相关推荐</h3>
      <div class="mvs">
        <div class="items">
          <div class="item"
          v-for="(relateMvObj, index) in relateMv"
          :key="index">
            <div class="img-wrap">
              <img :src="relateMvObj.cover" alt=""/>
              <span class="iconfont icon-play"></span>
              <div class="num-wrap">
                <div class="iconfont icon-play"></div>
                <div class="num">{{relateMvObj.playCount | changeCount}}</div>
              </div>
              <span class="time">{{relateMvObj.duration | changeTime}}</span>
            </div>
            <div class="info-wrap">
              <div class="name">{{relateMvObj.name}}</div>
              <div class="singer">{{relateMvObj.artistName}}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import axios from 'axios'

export default {
  data () {
    return {
      videoUrl: '',
      relateMv: [],
      mvInfoObj: {},
      iconInfo: '',
      limit: 10,
      page: 1,
      total: 20,
      newCommentList: [],
      hotCommentList: []
    }
  },
  // filters: {
  //   changeTime (value) {
  //     let min = parseInt(value / 1000 / 60)
  //     if (min < 10) min = '0' + min
  //     let sec = parseInt((value / 1000) % 60)
  //     if (sec < 10) sec = '0' + sec
  //     const time = `${min}分${sec}秒`
  //     return time
  //   },
  //   changeCount (value) {
  //     if (value > 100000) {
  //       const playCount = parseInt(value / 100000) + '万'
  //       return playCount
  //     }
  //   }
  // },
  created () {
    this.loadMv()
    this.loadRelatedMv()
    this.loadMvInfo()
    this.loadComment()
  },
  methods: {
    loadMv () {
      axios({
        url: 'https://autumnfish.cn/mv/url',
        method: 'get',
        params: {
          id: this.$route.query.q
        }
      }).then(res => {
        const { url } = res.data.data
        this.videoUrl = url
        // console.log(res)
      })
    },
    // 相关mv
    loadRelatedMv () {
      axios({
        url: 'https://autumnfish.cn/simi/mv',
        method: 'get',
        params: {
          id: this.$route.query.q
        }
      }).then(res => {
        const { mvs } = res.data
        this.relateMv = mvs
        // console.log(res)
      })
    },
    // mv信息
    loadMvInfo () {
      axios({
        url: 'https://autumnfish.cn/mv/detail',
        method: 'get',
        params: {
          id: this.$route.query.q
        }
      }).then(res => {
        const { data } = res.data
        this.mvInfoObj = data
        // console.log(res)
        this.loadMvSinger(this.mvInfoObj.artists[0].id)
      })
    },
    // 歌手信息
    loadMvSinger (id) {
      axios({
        url: 'https://autumnfish.cn/artists',
        method: 'get',
        params: {
          id
        }
      }).then(res => {
        const { iconInfo } = res.data.artist.picUrl
        this.iconInfo = iconInfo
        // console.log(res)
      })
    },
    // 精彩评论
    loadComment () {
      axios({
        url: 'https://autumnfish.cn/comment/mv',
        method: 'get',
        params: {
          id: this.$route.query.q,
          limit: this.limit,
          offset: (this.page - 1) * this.limit
        }
      }).then(res => {
        const { comments, hotComments, total } = res.data
        this.total = total
        // 最新评论
        this.newCommentList = comments
        this.hotCommentList = hotComments
        // console.log(res.data)
      })
    },
    handleCurrentChange (page) {
      this.page = page
      this.loadComments()
    }
  }
}
</script>
